﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Csla;
using OpenExpressApp.MetaAttribute;
using OpenExpressApp.MetaModel;
using OpenExpressApp.MetaModel.Audit;

namespace OpenExpressApp.Library.Audit
{
    [Serializable]
    [BusinessObject("f3a9e96b-2211-4684-b608-839c87da05a0")]
    public partial class AuditItemConditionCriteria : BusinessBase<AuditItemConditionCriteria>, IQueryObject
    {
        public AuditItemConditionCriteria()
        {
            //默认的查询起始时间和终止时间
            this.StartTime = DateTime.Today.AddMonths(-1);
            this.EndTime = DateTime.Today.AddDays(0d); ;
        }

        #region Properties

        /// <summary>
        /// 标题关键字
        /// </summary>
        private static PropertyInfo<string> TitleKeyWordsProperty =
            RegisterProperty(new PropertyInfo<string>("TitleKeyWords"));
        [EntityProperty]
        [ShowInDetail, Label("标题关键字")]
        public string TitleKeyWords
        {
            get
            {
                return GetProperty(TitleKeyWordsProperty);
            }
            set
            {
                SetProperty(TitleKeyWordsProperty, value);
            }
        }

        /// <summary>
        /// 内容关键字
        /// </summary>
        private static PropertyInfo<string> ContentKeyWordsProperty =
            RegisterProperty(new PropertyInfo<string>("ContentKeyWords"));
        [EntityProperty]
        [ShowInDetail, Label("内容关键字")]
        public string ContentKeyWords
        {
            get
            {
                return GetProperty(ContentKeyWordsProperty);
            }
            set
            {
                SetProperty(ContentKeyWordsProperty, value);
            }
        }

        /// <summary>
        /// 用户名关键字
        /// </summary>
        private static PropertyInfo<string> UserKeyWordsProperty =
            RegisterProperty(new PropertyInfo<string>("UserKeyWords"));
        [EntityProperty]
        [ShowInDetail, Label("用户名关键字")]
        public string UserKeyWords
        {
            get
            {
                return GetProperty(UserKeyWordsProperty);
            }
            set
            {
                SetProperty(UserKeyWordsProperty, value);
            }
        }

        /// <summary>
        /// 机器名关键字
        /// </summary>
        private static PropertyInfo<string> MachineKeyWordsProperty =
            RegisterProperty(new PropertyInfo<string>("MachineKeyWords"));
        [EntityProperty]
        [ShowInDetail, Label("机器名关键字")]
        public string MachineKeyWords
        {
            get
            {
                return GetProperty(MachineKeyWordsProperty);
            }
            set
            {
                SetProperty(MachineKeyWordsProperty, value);
            }
        }

        /// <summary>
        /// 模块名
        /// </summary>
        private static PropertyInfo<Guid?> BusinessObjectInfoIdProperty =
          RegisterProperty(new PropertyInfo<Guid?>("BusinessObjectInfoId"));
        [Required]
        [EntityProperty]
        [ShowInDetail, Label("模块名")]
        [Lookup("BusinessObjectInfo", DataSourceProperty = "BusinessObjectInfoDataSouce")]
        public Guid? BusinessObjectInfoId
        {
            get
            {
                return GetProperty(BusinessObjectInfoIdProperty);
            }
            set
            {
                SetProperty(BusinessObjectInfoIdProperty, value);
            }
        }
        /// <summary>
        /// 模块名（实际用于传输的数据）
        /// </summary>
        public string ModuleName { get; private set; }
        [NotUndoable, NonSerialized]
        private BusinessObjectInfo _BusinessObjectInfo;
        public BusinessObjectInfo BusinessObjectInfo
        {
            get
            {
                return this._BusinessObjectInfo;
            }
            set
            {
                this._BusinessObjectInfo = value;

                this.OnPropertyChanged("BusinessObjectInfo");

                if (value != null)
                {
                    this.ModuleName = value.Label;
                }
                else
                {
                    this.ModuleName = null;
                }
            }
        }
        [NotUndoable, NonSerialized]
        private IList<BusinessObjectInfo> _businessObjectInfoDataSouce;
        public IList<BusinessObjectInfo> BusinessObjectInfoDataSouce
        {
            get
            {
                if (_businessObjectInfoDataSouce == null)
                {
                    _businessObjectInfoDataSouce = ApplicationModel.GetAllModules().ToList();
                }
                return _businessObjectInfoDataSouce;
            }
        }

        /// <summary>
        /// 日志类型
        /// </summary>
        private static PropertyInfo<AuditLogType> AuditLogTypeProperty =
            RegisterProperty(new PropertyInfo<AuditLogType>("AuditLogType"));
        [EntityProperty]
        [ShowInDetail, Label("日志类型")]
        public AuditLogType AuditLogType
        {
            get
            {
                return GetProperty(AuditLogTypeProperty);
            }
            set
            {
                SetProperty(AuditLogTypeProperty, value);
            }
        }

        /// <summary>
        /// 起始时间
        /// </summary>
        private static PropertyInfo<DateTime> StartTimeProperty =
            RegisterProperty(new PropertyInfo<DateTime>("StartTime"));
        [EntityProperty]
        [ShowInDetail, Label("起始时间")]
        public DateTime StartTime
        {
            get
            {
                return GetProperty(StartTimeProperty);
            }
            set
            {
                SetProperty(StartTimeProperty, value);
            }
        }

        /// <summary>
        /// 终止时间
        /// </summary>
        private static PropertyInfo<DateTime> EndTimeProperty =
            RegisterProperty(new PropertyInfo<DateTime>("EndTime"));
        [EntityProperty]
        [ShowInDetail, Label("终止时间")]
        public DateTime EndTime
        {
            get
            {
                return GetProperty(EndTimeProperty);
            }
            set
            {
                SetProperty(EndTimeProperty, value);
            }
        }

        #endregion

        public void CheckRules() { }
    }
}
